package com.cmnit.analysis.service


import com.cmnit.analysis.dao.TrafficOutsideDao
import com.cmnit.analysis.util.{ConfigurationManager, ServiceUtil}
import org.apache.log4j.Logger

class TrafficOutsideService {
  private val logger: Logger = Logger.getLogger(this.getClass)
  private val dao = new TrafficOutsideDao

  def service(time: String): Unit = {
    // 获取加工账期（默认当前时间的前一天）
    val sqlTime = ServiceUtil.getAcctInfo(time)
    val acctTime = ServiceUtil.transformationTimeFormat(time)
    logger.info("加工账期时间：" + acctTime)

    // 删除需要插入的账期数据
    dao.delete(ConfigurationManager.getProperty("trafficOutside.table"), ConfigurationManager.getProperty("trafficOutside.time"), acctTime)

    // 写入数据
    dao.write(ConfigurationManager.getProperty("trafficOutside.table"), dao.trafficOutside(ServiceUtil.getAcctFourString(time), sqlTime, acctTime))

    // 查看写入结果
    dao.read(ConfigurationManager.getProperty("trafficOutside.table"), ConfigurationManager.getProperty("trafficOutside.time"), acctTime)
  }
}
